Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Using object references

Because classes in Progress are strongly-typed, you can cast an object reference as needed to allow a single variable or temp-table field to hold a reference to a variety of types. If you define a variable or temp-table field as being for class Progress.Lang.Object, you can use it to store an object reference for any class type. If you want to access public data members or methods defined for the object as a subclass of the specified class type, you can cast the object reference to the type of that subclass (or lower in the class hierarchy). Otherwise, Progress catches any attempts to reference this subclass functionality as a compiler error. For more information on casting, see the "Assignment and the CAST function" section.

If you need to keep track of a collection of object references, for example for all the class instances running in a session, you can create a temp-table with a field of type Progress.Lang.Object. You can then store any object reference in that field. For more information on defining and using temp-table fields to reference class-based objects, see the "Defining an object reference as a field in a temp-table" section.

You can then use the temp-table to retrieve a Progress.Lang.Object reference and cast it to the appropriate class or you can use built-in Progress.Lang.Object methods to return information about the object. For example, to display the class type name for each object reference saved in a temp-table you might write the following code fragment:

DEFINE TEMP-TABLE ttObjHolder NO-UNDO 
        FIELD objRef AS CLASS Progress.Lang.Object. 
... 
FOR EACH ttObjHolder: 
    MESSAGE objRef:GetClass( ):TypeName. 
END. 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095